package patterns.structures.composite.net;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;


public abstract class CompositeEquipment extends Equipment {

	private int i=0;
	
	private List equipment=new ArrayList();
	
	public CompositeEquipment(String name) {
		super(name);
	}

	@Override
	public double netPrice() {
		double netPrice=0;
		Iterator itr=equipment.iterator();
		while(itr.hasNext())
			netPrice+=((Equipment)itr.next()).netPrice();
		return netPrice;
	}

	@Override
	public double discountPrice() {
		double discountPrice=0;
		Iterator itr=equipment.iterator();
		while(itr.hasNext())
			discountPrice+=((Equipment)itr.next()).discountPrice();
		return discountPrice;
	}

	public boolean add(Equipment equipment){
		this.equipment.add(equipment);
		return true;
	}
 
	public Iterator itr(){
		return equipment.iterator();
	}

	public boolean hasNext(){
		return this.i<equipment.size();
	}
	
	public Object next(){
		if(hasNext()){
			return  equipment.get(i++);
		}else
			return new NoSuchElementException();
	}
}
